<?php
namespace Common\Model;
use Common\Model\AiModel;
class AuthModel extends AiModel {
    public function addAuth($auth){
        if($auth['auth_id'])
            $new_id = $auth['auth_id'];
        else
            $new_id = $this->add($auth);
       
        if($auth['auth_pid']==0){
            $auth_path = $new_id;
        }else{
            $pinfo = $this -> find($auth['auth_pid']); //查询出父级的记录信息
            $p_path = $pinfo['auth_path']; //父级全路径
            $auth_path = $p_path."-".$new_id;
        }
        if($auth['auth_level']){
            $auth_level = $auth['auth_level'];
        }else{
            $auth_level = count(explode('-',$auth_path))-1;
        }
         
        $dt = array(
            'auth_id'    => $new_id,
            'auth_name'  => $auth['auth_name'],
            'auth_pid'   => $auth['auth_pid'],
            'admin_name' => $auth['admin_name'],
            'auth_c'     => $auth['auth_c'],
            'auth_a'     => $auth['auth_a'],
            'auth_path'  => $auth_path,
            'auth_level' => $auth_level,
        );
        return $this -> save($dt);
    }
}